<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>注册</title>
    <link rel="stylesheet" href="../css/zc.css" />
    <script src="../js/ajax.js"></script>
  </head>
  <body>
    <footer>
      <div class="aa">
        <p>会员注册</p>
        <span>已注册<a href="./dl.html">直接登录</a></span>
      </div>
      <!-- 密码由8-20位组成,数字和符号组成 -->
      <div class="bb">
        <input type="text" placeholder="账号" /><br />
        <input type="password" placeholder="密码" /><br />
        <input type="password" placeholder="请再次输入密码" /> <br />
        <input id="kk" type="button" value="注册" /> <span></span>
        <br />
        <div class="box"><span></span></div>
        <input type="checkbox" class="test" />我已阅读并接受以下条款：<a
          href="https://h5rsc.vip.com/h5rscSupportClause/h5rscSupportClause/index.html"
          >《唯品会服务条款》</a
        ><br />
        <a href="https://www.vip.com/privacy">《唯品会基本功能隐私政策》</a
        ><br />
      </div>
    </footer>

    <script>
      const baseUrl = "http://localhost:8888";
      let p = document.querySelector("span");
      let inp = document.querySelectorAll("input");
      let kk = document.querySelector(".test");
      //点击确定注册按钮实现以下功能

      inp[3].onclick = function () {
        if (kk.checked == true) {
          let params = {
            username: inp[0].value,
            password: inp[1].value,
            rpassword: inp[2].value,
            nickname: inp[4].value,
          };
          const baseUrl = "http://localhost:8888";
          ajax({
            url: baseUrl + "/users/register",
            type: "post",
            params,
            fn(data) {
              let datas = JSON.parse(data);
              console.log(datas);
              if (datas.code == 0) {
               var name = '请重新输入密码';
          var htmlStr = `<div><span>${name}</span></div>`
          document.querySelector('.box').innerHTML = htmlStr;
              }
              if (datas.code == 1) {
                location.href = "./dl.html";
              }
            },
          });
        } else {
          var name = "请同意协议,后继续注册";
          var htmlStr = `<div><span>${name}</span></div>`;

          document.querySelector(".box").innerHTML = htmlStr;
        }
      };
    </script>
  </body>
</html>
